//
// Created by 11510 on 2024/6/12.
//

#ifndef LOG4SINGLE_LOGGER_H
#define LOG4SINGLE_LOGGER_H
#include <log4cpp/Category.hh>

/**
 * inline不可，必须用宏
 */
#define sumPrefix(msg) string("[") \
        .append(__FILE__)          \
        .append(" ")               \
        .append(__func__ )         \
        .append(" ")               \
        .append(std::to_string(__LINE__)) \
        .append("]")               \
        .append(msg).c_str()

#define LogWarn(msg) Logger::getInstance()->warn(sumPrefix(msg))

class Logger {
public:
    static Logger* getInstance();
    static void destroy();

    void warn(const char *msg);
    void error(const char *msg);
    void debug(const char *msg);
    void info(const char *msg);

private:
    Logger();
    ~Logger();

    Logger(Logger &rhs) = delete;
    Logger &operator=(const Logger &rhs) = delete;

    log4cpp::Category &_cat;
    static Logger *_pInstance;
};


#endif //LOG4SINGLE_LOGGER_H
